﻿//----------------------------------------------------------------
// Copyright (c) 2011-2013 
// All rights reserved.
// Author: Ben DaoWei 
// Contact: bendaowei@gmail.com
// Web Link: http://xnaeditor.codeplex.com
// ----------------------------------------------------------------

namespace UnityEngine.Components
{
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Graphics;
    using UnityEngine.Core;
    using System.Xml;
    using UnityEngine.IO;
    using System.Xml.Serialization;

    public class DebugCamera : Camera
    {
        [Editable]
        public float ZoomSpeed
        {
            get;
            set;
        }

        public DebugCamera()
            : base(null)
        {
            this.Reset();
        }

        public DebugCamera(GameObject gameObject)
            : base(gameObject)
        {
            this.Reset();
        }

        public void Reset()
        {
            this.ZoomSpeed = 100.0f;
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (this.GameObject.GameScene.Mode == SceneMode.DebugMode)
            {
                InputManager input = this.GameObject.GameScene.Game.InputManager;
                float seconds = (float)gameTime.ElapsedGameTime.TotalSeconds;

                if (input.MouseInRectangle() == true)
                {
                    int value = input.MouseDelta;
                    if (value == 0)
                    {
                        base.Update(gameTime);
                        return;
                    }
                    Vector3 normal = this.Position - this.LookAt;
                    normal.Normalize();
                    this.Position += normal * value * this.ZoomSpeed * seconds;
                }
            }
        }
    }
}
